//
//  IGHotCommnuityCollectionViewCell.m
//  jingdongfang
//
//  Created by BOE on 2017/8/28.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGHotCommnuityCollectionViewCell.h"
#import "IGCommunityModel.h"
#import "IGCommunityDetailVC.h"

@interface IGHotCommnuityCollectionViewCell ()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation IGHotCommnuityCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        __weak typeof(self) weakSelf = self;
        [self setTapActionWithBlock:^{
            IGCommunityDetailVC *detailVC = [[IGCommunityDetailVC alloc] initWithCid:weakSelf.model.cid type:GROUP_TITLE_GROUP_DETAILS];
            [UIViewController ig_pushViewController:detailVC animated:YES];
        }];
        
        UIView *view = [[UIView alloc] init];
        [self.contentView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.width.mas_equalTo(141);
        }];

        _imgView = [[UIImageView alloc] init];
        _imgView.backgroundColor = [UIColor mainBackgroundColor];
        [view addSubview:_imgView];

        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor c3Color];
        _titleLabel.font = [UIFont font16];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        [_imgView addSubview:_titleLabel];

        [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.mas_equalTo(0);
            make.bottom.mas_equalTo(-12.5);
        }];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
            make.centerX.mas_equalTo(_imgView.mas_centerX);
            make.centerY.mas_equalTo(_imgView.mas_centerY);
        }];
    }
    return self;
}

- (void)setModel:(IGCommunityModel *)model {
    _model = model;
    
    [_imgView sd_setImageWithURL:[NSURL URLWithString:model.cImgUrl]];
    _titleLabel.text = model.cTitle;
}

@end
